﻿using Goooodbye.Core.Repositories;
using Goooodbye.Core.Services;
using Goooodbye.Core.Services.Impl;
using Goooodbye.Infrastructure.Repositories;
using NLog;
using SimpleInjector;
using System;
using System.Reflection;
using System.Threading;

namespace Goooodbye.Presentation.ConsoleApp
{
    internal class Program
    {
        private static readonly Logger logger = LogManager.GetLogger(Assembly.GetExecutingAssembly().GetName().Name);
        private static readonly Container container;

        static Program()
        {
            container = new Container();

            container.Register(() => DbConnectionFactory.GetConnection(), Lifestyle.Singleton);
            container.Register<IDictRepository>(() => new DictRepository(DbConnectionFactory.GetConnection()));
            container.Register<IDictService, DictService>();

            container.Verify();
        }

        static void Main(string[] args)
        {
            logger.Trace("DIAGNOSTIC MESSAGE AT TRACE LEVEL");
            logger.Debug("DIAGNOSTIC MESSAGE AT DEBUG LEVEL");
            logger.Info("DIAGNOSTIC MESSAGE AT INFO LEVEL");
            logger.Warn("DIAGNOSTIC MESSAGE AT WARN LEVEL");
            logger.Error("DIAGNOSTIC MESSAGE AT ERROR LEVEL");
            logger.Fatal("DIAGNOSTIC MESSAGE AT FATAL LEVEL");
            for (int i = 0; i < 3; i++)
            {
                var t = new Thread(() =>
                {
                    var service = container.GetInstance<IDictService>();
                    var count = service.Query().Total;
                    Console.WriteLine($"dict count: {count}");
                });
                t.Start();
            }

            Console.WriteLine("Press any key to exit.");
            Console.ReadKey(true);
        }
    }
}
